/*
 * JHeuristics - The Java Meta-Heuritics Library
 * Copyright (C) 2004-2005, Universidade Federal de Campina Grande. All rights reserved.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.jheuristics.ga.operators.reproductors;

import org.jheuristics.Individual;
import org.jheuristics.ga.GAConfig;
import org.jheuristics.ga.GAStatus;
import org.jheuristics.ga.operators.Probability;
import org.jheuristics.ga.operators.Reproductor;

/**
 * TODO
 *
 * @author Marcell Manfrin, marcell@ourgrid.org, Jan 9, 2006
 */
public abstract class AbstractReproductor implements Reproductor {
    private Probability probability;
    private int tryOuts;
    
    /**
     * TODO
     *
     * @param probability
     * @param tryOuts
     */
    public AbstractReproductor(Probability probability, int tryOuts) {
        super();
        setProbability(probability);
        setMaxBadReproductionAttempts(tryOuts);
    }

    /**
     * TODO
     *
     * @return
     * @see org.jheuristics.ga.operators.Reproductor#getRequiredNumberOfParents()
     */
    public abstract int getRequiredNumberOfParents();

    /**
     * TODO
     *
     * @param parents
     * @param status
     * @param config
     * @return
     * @see org.jheuristics.ga.operators.Reproductor#reproduce(org.jheuristics.Individual[], org.jheuristics.ga.GAStatus, org.jheuristics.ga.GAConfig)
     */
    public abstract Individual[] reproduce(Individual[] parents, GAStatus status, GAConfig config);

    /**
     * TODO
     *
     * @return Returns the probability.
     */
    public Probability getProbability() {
        return probability;
    }

    /**
     * TODO
     *
     * @param probability The probability to set.
     */
    public void setProbability(Probability probability) {
		if (null == probability) {
			// TODO: ERROR MSG
			throw new NullPointerException();
		}
        this.probability = probability;
    }

    /**
     * TODO
     *
     * @return
     */
    public int getMaxBadReproductionAttempts() {
        return tryOuts;
    }

    /**
     * TODO
     *
     * @param tryOuts
     */
    public void setMaxBadReproductionAttempts(int tryOuts) {
		if (0 > tryOuts) {
			// TODO: ERROR MSG
			throw new IllegalArgumentException();
		}
        this.tryOuts = tryOuts;
    }

}
